package com.datastructure.test.insertlistnode;


import java.util.Arrays;

public class InsertListNode {

    public static void main(String[] args) {
        InsertListNode insertListNode = new InsertListNode();
        int[] a = {1,3,4,5,7};
        ListNode insert = insertListNode.insert(a, 2);
        System.out.println(insert);
    }

    public ListNode insert (int[] A, int val) {
        // write code here
        int length = A.length;
        int[] B = new int[length +1];
        System.arraycopy(A,0,B,0,length);
        B[length]=val;
        Arrays.sort(B);
        ListNode temp = null;
        ListNode cur;
        for (int i = B.length-1; i >= 0; i--) {
            cur=new ListNode(B[i]);
            cur.next=temp;
            temp=cur;
        }
        return temp;
    }
}
class ListNode {
   int val;
   ListNode next = null;
   public ListNode(int val) {
     this.val = val;
   }
 }
